$(function() {
    var $projectEntryTableForm = $(".projectEntry-table-form");
    var settings = {
        url: ctx + "projectEntry/list",
        pageSize: 10,
        queryParams: function(params) {
          return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                customer: $projectEntryTableForm.find("input[name='customer']").val().trim(),
                marketName: $projectEntryTableForm.find("input[name='marketName']").val().trim(),
                projectNo: $projectEntryTableForm.find("input[name='projectNo']").val().trim()
            };
        },
        columns: [{
                checkbox: true
            }, {
                field: 'customer',
                title: '客户'
            }, {
                field: 'marketName',
                title: '市场名'
            }, {
                field: 'projectNo',
                title: '项目代号'
            }, {
                field: 'projectBaseLine',
                title: '项目基线'
            }, {
                field: 'projectType',
                title: '项目类型'
            }, {
                field: 'typeName',
                title: '机型名'
            }, {
                field: 'memorySize',
                title: '内存大小'
            },{
                 field: 'createTime',
                 visible: false,
                 title: '创建时间'
            },{
                 field: 'updateTime',
                 visible: false,
                 title: '修改时间'
        }
        ]
    };

    $MB.initTable('projectEntryTable', settings);
});

function search() {
    $MB.refreshTable('projectEntryTable');
}

function refresh() {
    $(".projectEntry-table-form")[0].reset();
    search();
}

function deleteProjectEntry() {
    var selected = $("#projectEntryTable").bootstrapTable('getSelections');
    var selected_length = selected.length;
    if (!selected_length) {
        $MB.n_warning('请勾选需要删除的项目！');
        return;
    }
    var projectIds = "";
    for (var i = 0; i < selected_length; i++) {
        projectIds += selected[i].projectId;
        if (i !== (selected_length - 1)) projectIds += ",";
    }
    $MB.confirm({
        text: "确定删除选中的项目？",
        confirmButtonText: "确定删除"
    }, function() {
        $.post(ctx + 'projectEntry/delete', { "projectIds": projectIds }, function(r) {
            if (r.code === 0) {
                $MB.n_success(r.msg);
                refresh();
            } else {
                $MB.n_danger(r.msg);
            }
        });
    });
}

function importProjectEntryExcel(){
    $.post(ctx+"projectEntry/importExcel",$(".projectEntry-table-form").serialize(),function(r){
        if (r.code === 0) {
            window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $MB.n_warning(r.msg);
        }
    });
}

function exportProjectEntryExcel(){
	$.post(ctx+"projectEntry/excel",$(".projectEntry-table-form").serialize(),function(r){
		if (r.code === 0) {
			window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
		} else {
			$MB.n_warning(r.msg);
		}
	});
}

function exportProjectEntryCsv(){
	$.post(ctx+"projectEntry/csv",$(".projectEntry-table-form").serialize(),function(r){
		if (r.code === 0) {
			window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
		} else {
			$MB.n_warning(r.msg);
		}
	});


}

function uploadDate() {

}

